<?php
/*----------------------------------------------------------------------
 * 开放接口
 * Author: ming.nie
----------------------------------------------------------------------*/

namespace Home\Controller;
use Think\Controller;
class InterfaceController extends Controller {
    
    public function index(){
        $result = array();
		$result_manager = array(
			10000 => array('code'=>10000),
			10001 => array('code'=>10001),
			10002 => array('code'=>10002),
			10003 => array('code'=>10003),
			10004 => array('code'=>10004),
		);
		$status_code = 0;
		$class = I('request.class', '', 'strip_tags');
		$method = I('request.method', '', 'strip_tags');
		if(!empty($class) && !empty($method))
		{
            $class = "\Common\Logic\\".$class.'Logic';
			if(class_exists($class))
			{
				$obj = new $class();
				if(method_exists($obj, $method))
				{
					$params = $_REQUEST['params'];
					if($params){
						if(get_magic_quotes_gpc()){
							$params = stripslashes($params);
						}
						$params = json_decode($params, true);
					}
					$result['code'] = 10001;
					$result['data'] = $obj->$method($params);
					echo json_encode($result);
					
					//记录日志
					// $model = M('InterfaceLog');
					// $log_params = array();
					// $log_params['class'] = $class;
					// $log_params['method'] = $method;
					// $log_params['params'] = json_encode($params);
					// $log_params['result'] = json_encode($_REQUEST) .json_encode($_FILES);
					// $log_params['response'] = json_encode($result);
					// $log_params['create_time'] = time();
					// $model->data($log_params)->add();
					exit;
				}
				else
				{
					$status_code = 10004;
				}
			}
			else
			{
				$status_code = 10003;
			}
		}
		else
		{
			$status_code = 10002;
		}
		echo json_encode($result_manager[$status_code]);
    }
}